var mysql = require('mysql');

var pool = mysql.createPool({
    host            : '0.0.0.0',
    user            : 'root',
    password        : 'Yinhangzhangqi@2014',
    database        : 'love_nature_service',
    charset         : 'utf8mb4'
});

module.exports = {
    pool: pool,
    query: function (query, values, callback) {
        if(typeof values == "function") {
          callback = values;
          values = [];
        }
        pool.getConnection(function(err, connection) {
            if(err)
            {
                console.log(err);
                connection.release();
                callback.apply(this, arguments);
            }
            else
            {
                connection.query(query, values, function(err, results) {

                    connection.release();
                    if(err)
                    {
                        console.log(err);
                    }
                    callback.apply(this, arguments);
                });
            }
        });

    }
};
